package com.yunfei.api.financialCalculator;
import com.yunfei.api.financialCalculator.bo.FcjsqHouseCity;
import com.yunfei.api.financialCalculator.bo.HouseArea;
import com.yunfei.api.financialCalculator.contants.CalculatorContants;
import com.yunfei.api.financialCalculator.param.*;
import com.yunfei.api.financialCalculator.result.*;
import com.yunfei.api.financialCalculator.service.*;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.enums.ResultStatus;
import com.yunfei.enums.ZiNvJiaoYuCalResultStatus;
import com.yunfei.fegin.RedisFeignService;
import com.yunfei.mapper.aiiidb.*;
import com.yunfei.procedure.ZiNvJiaoYuCalProcedure;
import com.yunfei.ribbon.RedisServiceRibbon;
import com.yunfei.service.RedisService;
import com.yunfei.service.ValidMobileAndCodeService;
import com.yunfei.utils.jdbc.AiiidbUtil;
import com.yunfei.utils.string.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 理财计算器
 * @Author: zhengyunfei
 * @Date: 2018/6/15
 * @time:11:26
 */
@SuppressWarnings("ALL")
@RestController
@RequestMapping("/calculator")
@Api(value = CalculatorContants.NAMESPACE,tags =  CalculatorContants.NAMESPACE )
public class LiCaiCalApiController {
    @Autowired
    private TPersonalUserMapper tPersonalUserMapper;
    @Autowired
    private GetStatusMapper getStatusMapper;
    @Autowired
    private RedisFeignService redisFeignService;
    @Autowired
    private RedisService redisService;
    @Autowired
    private RedisServiceRibbon redisServiceRibbon;
    @Autowired
    private ValidMobileAndCodeService validMobileAndCodeService;
    @Autowired
    private Environment env;
    @Autowired
    private HourseCityMapper2 hourseCityMapper;
    @Autowired
    private StudyConfigMapper studyConfigMapper;
    /**
    * @Description: 统计计算器
    * @Author: zhengyunfei
    * @Date: 2019/7/8
    * @time:10:52
    */
    @PostMapping(value="/tongji")
    @ApiOperation(value =CalculatorContants.TONGJI,notes =CalculatorContants.TONGJI,position = 1,response = TongjiCalResult.class)
    @ResponseBody
    public Object tjjsq(TongjiCalParam param){
        ResultModel resultModel=TongJiCalService.cal(param,env);
        return resultModel.getData();
    }
    /**
     * @Description: 日期计算器
     * @Author: zhengyunfei
     * @Date: 2019/7/8
     * @time:10:52
     */
    @PostMapping(value="/riqi")
    @ApiOperation(value =CalculatorContants.RIQI,notes =CalculatorContants.RIQI,position = 1,response = RiQiCalResult.class)
    @ResponseBody
    public Object rqjsq(RiQiCalParam param){
        ResultModel resultModel= RiQiCalService.cal(param,env);
        return resultModel.getData();
    }
    /**
     * @Description: 固定收益类计算器FangChanCalParam
     * @Author: zhengyunfei
     * @Date: 2019/7/8
     * @time:10:52
     */
    @PostMapping(value="/gudingshouyi")
    @ApiOperation(value =CalculatorContants.GDSY,notes =CalculatorContants.GDSY,position = 1,response = GuDingShouYiLeiCalResult.class)
    @ResponseBody
    public Object gdsyjsq(GuDingShouYiLeiCalParam param) {
        ResultModel resultModel= GuDingShouYiLeiCalService.cal(param,env);
        return resultModel.getData();
    }
    /**
     * @Description: 房产类计算器-获取城市
     * @Author: zhengyunfei
     * @Date: 2019/7/8
     * @time:10:52
     */
    @GetMapping(value="/fangchan/getCity")
    @ApiOperation(value =CalculatorContants.FC_GET,notes =CalculatorContants.FC_GET_NOTES,position = 1,response = FcjsqHouseCity.class)
    @ResponseBody
    public Object getCity(){
        ResultModel resultModel=FangChanCalService.getCity(hourseCityMapper);
        return resultModel;
    }
    /**
     * @Description: 房产类计算器-获取街道
     * @Author: zhengyunfei
     * @Date: 2019/7/8
     * @time:10:52
     */
    @GetMapping(value="/fangchan/getAreaOrStreet")
    @ApiOperation(value =CalculatorContants.FC_STREET_QUERY,notes =CalculatorContants.FC_STREET_QUERY_NOTES,position = 1,response = HouseArea.class)
    @ResponseBody
    public Object getAreaOrStreet(HouseAreaParam param){
        ResultModel resultModel=FangChanCalService.getAreaOrStreet(param,env,hourseCityMapper);
        return resultModel;
    }
    /**
    * @Description: 房产类计算器-计算
    * @Author: zhengyunfei
    * @Date: 2019/7/9
    * @time:11:21
     */
    @PostMapping(value="/fangchan/cal")
    @ApiOperation(value =CalculatorContants.FC_CAL,notes =CalculatorContants.FC_CAL_NOTES,position = 1,response = FangChanCalResult.class)
    @ResponseBody
    public Object cal(FangChanCalParam param){
        ResultModel resultModel=FangChanCalService.cal(param,env,hourseCityMapper);
        return resultModel.getData();
    }
    /**
    * @Description: 养老计算器
    * @return: java.lang.Object
    * @Author: zhengyunfei
    * @Date: 2019/7/9
    * @time:14:57
    */
    @PostMapping(value="/yanglao/cal")
    @ApiOperation(value =CalculatorContants.YANGLAO_CAL,notes =CalculatorContants.YANGLAO_CAL,position = 1,response = YangLaoCalResult.class)
    @ResponseBody
    public Object yangLaoCal(YangLaoCalParam param){
        ResultModel resultModel= YangLaoCalService.cal(param,env);
        return resultModel.getData();
    }
    /**
     * @Description: 子女教育计算器-获取可以选择的阶段
     * @return: java.lang.Object
     * @Author: zhengyunfei
     * @Date: 2019/7/9
     * @time:14:57
     */
    @GetMapping(value="/zinvjiaoyu/get")
    @ApiOperation(value =CalculatorContants.ZINVJIAOYU_GET,notes =CalculatorContants.ZINVJIAOYU_GET_NOTES,position = 1,response = StudyConfigResult.class)
    @ResponseBody
    public Object get(ZiNvJiaoYuGetStudyParam param){
        ResultModel resultModel= new ResultModel();
        String childAge=param.getChildAge();
        if(StringUtil.isNullOrEmpty(childAge)){
            resultModel.setCode(ZiNvJiaoYuCalResultStatus.childAge.getCode());
            resultModel.setMessage(ZiNvJiaoYuCalResultStatus.childAge.getMessage());
            return resultModel;
        }
        Map<String,Object> queryMap=new HashMap<>();
        queryMap.put("childAge",childAge);
        List<StudyConfigResult> list=studyConfigMapper.list(queryMap);
        resultModel.setCode(ResultStatus.SUCCESS.getCode());
        resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        resultModel.setData(list);
        return resultModel;
    }
    /**
     * @Description: 子女教育计算器-极端
     * @return: java.lang.Object
     * @Author: zhengyunfei
     * @Date: 2019/7/9
     * @time:14:57
     */
    @GetMapping(value="/zinvjiaoyu/cal")
    @ApiOperation(value =CalculatorContants.ZINVJIAOYU_CAL,notes =CalculatorContants.ZINVJIAOYU_CAL,position = 1,response = ZiNvJiaoYuCalResult.class)
    @ResponseBody
    public Object cal(ZiNvJiaoYuCalParam param){
        ResultModel resultModel= new ResultModel();
        //校验参数
        String childAge=param.getChildAge();//子女年龄
        String wantAmt=param.getWantAmt();//需要的金额
        if(StringUtil.isNullOrEmpty(childAge)){
            resultModel.setCode(ZiNvJiaoYuCalResultStatus.childAge.getCode());
            resultModel.setMessage(ZiNvJiaoYuCalResultStatus.childAge.getMessage());
            return resultModel;
        }
        if(StringUtil.isNullOrEmpty(wantAmt)){
            resultModel.setCode(ZiNvJiaoYuCalResultStatus.wantAmt.getCode());
            resultModel.setMessage(ZiNvJiaoYuCalResultStatus.wantAmt.getMessage());
            return resultModel;
        }
        ZiNvJiaoYuCalResult result= new ZiNvJiaoYuCalProcedure().callProcedure(AiiidbUtil.getInstance(env),param);
        return result;
    }
    //获取利率
    @GetMapping(value="/rate/get")
    @ApiOperation(value =CalculatorContants.GET_RATE,notes =CalculatorContants.GET_RATE,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object getRate( ){
        ResultModel resultModel= new ResultModel();
        //查询利率
        String rate=hourseCityMapper.getRate();
        resultModel.setCode(ZiNvJiaoYuCalResultStatus.SUCCESS.getCode());
        resultModel.setMessage(ZiNvJiaoYuCalResultStatus.SUCCESS.getMessage());
        resultModel.setData(rate);
        return resultModel;
    }
}
